package cn.dgiot.fd.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.dgiot.fd.dao.IPLCModelFlowDAO;
import cn.dgiot.fd.model.DeviceStateModel;
import cn.dgiot.fd.model.PLCModelFlow;
import cn.dgiot.fd.service.IDeviceStateService;
import cn.dgiot.fd.service.IPLCModelFlowService;

/**
 * [下位机型号流水]
 * @author
 *
 */
@Service
public class PLCModelFlowServiceImpl implements IPLCModelFlowService{
 
	@Autowired
	private IPLCModelFlowDAO plcModelFlowDAO;

	@Autowired
	private IDeviceStateService deviceStateService;
	
	@Override
	public void insertPLCModel(PLCModelFlow plcModelFlow) {
		List<PLCModelFlow> plcModelList = new ArrayList<PLCModelFlow>();
		String deviceName = plcModelFlow.getDeviceName();
		DeviceStateModel deviceStateModel = new DeviceStateModel();
    	deviceStateModel.setDeviceName(deviceName);
    	deviceStateModel.setProductKey(plcModelFlow.getProductKey());
    	DeviceStateModel deviceStateModelResult = deviceStateService.getDeviceState(deviceStateModel);
		
    	PLCModelFlow param = new PLCModelFlow();
    	param.setId(UUID.randomUUID().toString().replace("-", ""));
		param.setIotId(deviceStateModelResult.getIotId());
		param.setDeviceName(deviceName);
		param.setProductKey(plcModelFlow.getProductKey());
		param.setPlcCode(plcModelFlow.getPlcCode());
		param.setDpno(plcModelFlow.getDpno());
		param.setReportTime(plcModelFlow.getReportTime());
		param.setRequestId(plcModelFlow.getRequestId());
		plcModelList.add(param);
		plcModelFlowDAO.insertPLCModel(plcModelList);
	}

	@Override
	public void updatePLCModel(PLCModelFlow plcModelFlow) {
		// TODO Auto-generated method stub
		plcModelFlowDAO.updatePLCModel(plcModelFlow);
	}

}
